package com.example.service.impl;

import com.example.dao.UserDao;
import com.example.entity.User;
import com.example.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.HashMap;
import java.util.Map;

@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private UserDao userDao;

    @Override
    public User authenticate(String username, String password, String role) {
        Map<String, String> params = new HashMap<>();
        params.put("username", username);
        params.put("role", role);

        User user = userDao.findByUsernameAndRole(params);
        if (user != null && user.getPassword().equals(password)) {
            return user;
        }
        return null;
    }
    @Override
    public int saveUser(User user) {
        // 实际项目中应该对密码进行加密
        return userDao.save(user);
    }
}